package com.ty.springtask;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ScheduledTask {
    private  int  i = 0;
    // @Scheduled(fixedDelay = 3000)  //fixedDelay  上次结束到下次开始的间隔时间
    public void task1() {
        log.debug("fixedDelay doing ->  "+i);
        i++;
        if(i == 5 || i == 7){
            ThreadUtil.safeSleep(5000);
        }
    }
    //@Scheduled(initialDelayString = "${task2.initialDelay}",fixedDelayString = "${task2.fixedDelay}")  //fixedDelay  上次结束到下次开始的间隔时间
    public void task2() {
        log.debug("initialDelay+fixedDelay doing ->  "+i);

    }

    //@Scheduled(fixedRate = 5000)  //fixedRate  上次开始到下次开始间隔的时间5s
    //@Async("asyncScheduledPool")
    public void task3() {
        log.debug("fixedRate doing ->  "+i);
        i++;
        if(i == 5 || i == 7){
            ThreadUtil.safeSleep(8000);
        }
    }

    // @Scheduled(cron = "0/2 * * * * ?" )  //corn 表达式
    // @Async("asyncScheduledPool")
    public void task4() {
        log.debug("corn doing ->  "+i);
        i++;

    }}
